/**
 * 时间戳转剩余时间
 * @param {Number} timestamp 时间戳
 * @returns 小时/分钟/秒/天
 */
export const formatTimeRemaining = (timestamp, isSubtract = true) => {
  const date = +new Date(timestamp)
  const now = +new Date()
  const diff = date - now

  const seconds = Math.floor(((isSubtract ? diff : timestamp) / 1000) % 60)
  const minutes = Math.floor(((isSubtract ? diff : timestamp) / 1000 / 60) % 60)
  const hours = Math.floor(
    ((isSubtract ? diff : timestamp) / (1000 * 60 * 60)) % 24
  )
  const days = Math.floor(
    (isSubtract ? diff : timestamp) / (1000 * 60 * 60 * 24)
  )

  return {
    seconds,
    minutes,
    hours,
    days
  }
}
